Skip to content

fix: improve onboard plugin icon handling#345

Merged
mhduiy merged 1 commit into
linuxdeepin:masterfrom
mhduiy:icon
Aug 5, 2025
Merged

fix: improve onboard plugin icon handling#345
mhduiy merged 1 commit into
linuxdeepin:masterfrom
mhduiy:icon

Conversation

@mhduiy

@mhduiy mhduiy commented Aug 4, 2025

Copy link
Copy Markdown
Contributor
  1. Replaced custom OnboardItem with CommonIconButton for consistent icon behavior
  2. Simplified icon loading logic by removing redundant fallback checks
  3. Added proper QIcon and QLogging includes
  4. Removed obsolete OnboardItem class files
  5. Improved icon fallback mechanism in CommonIconButton

fix: 改进屏幕键盘插件图标处理

  1. 使用 CommonIconButton 替代自定义的 OnboardItem 以获得一致的图标行为
  2. 通过移除冗余的回退检查简化了图标加载逻辑
  3. 添加了适当的 QIcon 和 QLogging 头文件包含
  4. 移除了过时的 OnboardItem 类文件 5 改进了 CommonIconButton 中的图标回退机制

Summary by Sourcery

Replace custom OnboardItem with CommonIconButton and streamline icon handling.

Enhancements:

  • Use CommonIconButton instead of the obsolete OnboardItem for consistent plugin icon behavior
  • Simplify icon loading logic and improve the fallback mechanism in CommonIconButton
  • Add missing QIcon and QLogging header includes
  • Remove obsolete OnboardItem class files

@mhduiy mhduiy requested a review from 18202781743 August 4, 2025 10:45
@sourcery-ai

sourcery-ai Bot commented Aug 4, 2025

Copy link
Copy Markdown

Reviewer's Guide

Replaces the custom OnboardItem widget with CommonIconButton in OnboardPlugin for consistent icon handling, removes legacy files and redundant fallback logic, and ensures proper includes and a robust icon fallback mechanism.

Class diagram for OnboardPlugin refactor (OnboardItem replaced by CommonIconButton)

classDiagram
    class OnboardPlugin {
        - bool m_pluginLoaded
        - bool m_startupState
        - QScopedPointer<CommonIconButton> m_onboardIcon
        - QScopedPointer<Dock::TipsWidget> m_tipsLabel
        - QScopedPointer<QuickPanel> m_quickPanel
        + QWidget* itemWidget(const QString &itemKey)
        + QWidget* itemTipsWidget(const QString &itemKey)
        + void displayModeChanged(const Dock::DisplayMode displayMode)
        + void loadPlugin()
    }
    class CommonIconButton {
        + void setIcon(const QString &icon, const QString &fallback, const QString &state)
    }
    OnboardPlugin --> CommonIconButton : uses
    OnboardPlugin --> QuickPanel : uses
    OnboardPlugin --> TipsWidget : uses
Loading

File-Level Changes

Change Details Files
Use CommonIconButton instead of custom OnboardItem in OnboardPlugin
  • Swap QScopedPointer from OnboardItem to CommonIconButton in header
  • Update itemWidget() and displayModeChanged() to reference m_onboardIcon
  • Instantiate CommonIconButton in loadPlugin(), set fixed size and default icon
plugins/dde-dock/onboard/onboardplugin.cpp
plugins/dde-dock/onboard/onboardplugin.h
Simplify and enhance icon loading logic in CommonIconButton
  • Remove combined-fromTheme call with two args
  • First attempt to load primary icon, then fall back if null
  • Retain default icon as last resort
plugins/dde-dock/common/commoniconbutton.cpp
Remove obsolete OnboardItem class
  • Delete OnboardItem implementation and header
  • Remove onboarditem include from plugin header
plugins/dde-dock/onboard/onboarditem.cpp
plugins/dde-dock/onboard/onboarditem.h
plugins/dde-dock/onboard/onboardplugin.h
Add missing QIcon and QLogging includes
  • Include QIcon where icon operations occur
  • Include QLoggingCategory for logging support
plugins/dde-dock/common/commoniconbutton.cpp
plugins/dde-dock/onboard/onboardplugin.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mhduiy - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `plugins/dde-dock/onboard/onboardplugin.cpp:185` </location>
<code_context>
-    m_onboardItem.reset(new OnboardItem);
+    m_onboardIcon.reset(new CommonIconButton);
+    m_onboardIcon->setFixedSize(Dock::DOCK_PLUGIN_ITEM_FIXED_SIZE);
+    m_onboardIcon->setIcon(":/icons/icon/keyboard-symbolic.svg");

     m_proxyInter->itemAdded(this, pluginName());
</code_context>

<issue_to_address>
Hardcoded icon path may reduce theme flexibility.

Consider using a theme icon name instead of a hardcoded resource path if supporting theme customization is required.

Suggested implementation:

```cpp
    m_onboardIcon.reset(new CommonIconButton);
    m_onboardIcon->setFixedSize(Dock::DOCK_PLUGIN_ITEM_FIXED_SIZE);
    // Use theme icon name for better theme flexibility
    m_onboardIcon->setIcon("input-keyboard");

```

If `CommonIconButton::setIcon` does not support theme icon names directly, you may need to use `QIcon::fromTheme("input-keyboard", QIcon(":/icons/icon/keyboard-symbolic.svg"))` to provide a fallback. For example:

    m_onboardIcon->setIcon(QIcon::fromTheme("input-keyboard", QIcon(":/icons/icon/keyboard-symbolic.svg")));

Adjust as needed based on how `CommonIconButton` expects its icon to be set.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

m_onboardItem.reset(new OnboardItem);
m_onboardIcon.reset(new CommonIconButton);
m_onboardIcon->setFixedSize(Dock::DOCK_PLUGIN_ITEM_FIXED_SIZE);
m_onboardIcon->setIcon(":/icons/icon/keyboard-symbolic.svg");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Hardcoded icon path may reduce theme flexibility.

Consider using a theme icon name instead of a hardcoded resource path if supporting theme customization is required.

Suggested implementation:

    m_onboardIcon.reset(new CommonIconButton);
    m_onboardIcon->setFixedSize(Dock::DOCK_PLUGIN_ITEM_FIXED_SIZE);
    // Use theme icon name for better theme flexibility
    m_onboardIcon->setIcon("input-keyboard");

If CommonIconButton::setIcon does not support theme icon names directly, you may need to use QIcon::fromTheme("input-keyboard", QIcon(":/icons/icon/keyboard-symbolic.svg")) to provide a fallback. For example:

m_onboardIcon->setIcon(QIcon::fromTheme("input-keyboard", QIcon(":/icons/icon/keyboard-symbolic.svg")));

Adjust as needed based on how CommonIconButton expects its icon to be set.

1. Replaced custom OnboardItem with CommonIconButton for consistent
icon behavior
2. Simplified icon loading logic by removing redundant fallback checks
3. Added proper QIcon and QLogging includes
4. Removed obsolete OnboardItem class files
5. Improved icon fallback mechanism in CommonIconButton

fix: 改进屏幕键盘插件图标处理

1. 使用 CommonIconButton 替代自定义的 OnboardItem 以获得一致的图标行为
2. 通过移除冗余的回退检查简化了图标加载逻辑
3. 添加了适当的 QIcon 和 QLogging 头文件包含
4. 移除了过时的 OnboardItem 类文件
5 改进了 CommonIconButton 中的图标回退机制
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, mhduiy

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

代码审查意见:

  1. commoniconbutton.cpp文件中,setIcon函数中新增的if语句可以简化,直接使用QIcon::fromTheme的返回值即可,不需要额外的if判断。修改后的代码如下:
m_icon = QIcon::fromTheme(tmp).isNull() ? QIcon::fromTheme(tmpFallback) : QIcon::fromTheme(tmp);
  1. onboarditem.cpp文件中,paintEvent函数中使用了std::min来获取宽度和高度的最小值,但是没有考虑到width()height()可能为0的情况。应该添加对宽度和高度的检查,避免潜在的除零错误。

  2. onboarditem.cpp文件中,loadSvg函数中使用了QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps),但是这个函数在Qt 5.14及以上版本中已经被弃用。应该使用QGuiApplication::testAttribute(Qt::AA_UseHighDpiPixmaps)来代替。

  3. onboardplugin.cpp文件中,loadPlugin函数中创建CommonIconButton对象时,应该使用m_onboardIcon.reset(new CommonIconButton)来确保之前的对象被正确释放。

  4. onboardplugin.cpp文件中,loadPlugin函数中设置CommonIconButton的图标时,应该使用m_onboardIcon->setIcon(":/icons/icon/keyboard-symbolic.svg")来代替m_onboardIcon->setFixedSize(Dock::DOCK_PLUGIN_ITEM_FIXED_SIZE)

  5. onboardplugin.h文件中,OnboardPlugin类中包含了OnboardItem类的头文件,但是OnboardItem类已经被删除。应该移除#include "onboarditem.h"这一行。

  6. onboardplugin.h文件中,OnboardPlugin类中包含了CommonIconButton类的头文件,但是CommonIconButton类可能没有定义。应该检查CommonIconButton类的定义,并确保它被正确包含。

  7. onboardplugin.h文件中,OnboardPlugin类中包含了QuickPanelTipsWidget类的头文件,但是这些类是否被正确包含需要进一步确认。

  8. onboardplugin.h文件中,OnboardPlugin类中包含了Dock类的头文件,但是Dock类是否被正确包含需要进一步确认。

  9. onboardplugin.h文件中,OnboardPlugin类中包含了PluginsItemInterfaceV2类的头文件,但是PluginsItemInterfaceV2类是否被正确包含需要进一步确认。

以上是针对代码审查意见的详细说明,希望能够对你有所帮助。

@mhduiy mhduiy merged commit 722758c into linuxdeepin:master Aug 5, 2025
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants